package com.hyc.myvideo.ui.activity.my;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.acmenxd.toaster.Toaster;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.hyc.myvideo.R;
import com.hyc.myvideo.data.api.model.BaseResult;
import com.hyc.myvideo.data.api.model.ModelCommission;
import com.hyc.myvideo.ui.base.BaseFActivity;

import butterknife.BindView;
import butterknife.OnClick;


/**
 * 佣金
 * @author gyb
 * @version 1.0
 * @created 2017/07/20
 */
public class CommissionActivity extends BaseFActivity {
    @BindView(R.id.l_layout)
    LinearLayout layout;
    /**课程佣金*/
    @BindView(R.id.commission_t_course)TextView textViewCourse;
    /**礼物*/
    @BindView(R.id.commission_t_gift)TextView textViewGift;
    @Override
    public int getContentViewId() {
        return R.layout.activity_commission;
    }
    @Override
    protected void initView() {
        setLeftBtnClick(true, getIntent().getStringExtra("title"));
    }

    @Override
    protected void initData() {
        api.requestCommissionData();
    }

    @Override
    protected void oNext(String r, String method) {
        BaseResult<ModelCommission> result = JSONObject.parseObject(r, new TypeReference<BaseResult<ModelCommission>>(){});
        if(result.isCode()){
            setViewDate(result.getResult());
        }else{
            layout.setVisibility(View.GONE);
            Toaster.show(result.getMsg());
        }
    }

    @Override
    protected void oError() {

    }

    /***
     * 展示主播佣金
     * @param commission
     */
    private void setViewDate(ModelCommission commission){
        layout.setVisibility(View.VISIBLE);
        textViewCourse.setText(String.format(getStr(R.string.huc_my_course_money),new java.text.DecimalFormat("0.00").format(commission.getCommission())));
        textViewGift.setText(String.format(getStr(R.string.huc_my_gift),commission.getDirect_gift_luzhu()));
        Drawable drawable = ContextCompat.getDrawable(this,R.mipmap.icon_my_dew);
        drawable.setBounds(0, 0, 30, 50);
        textViewGift.setCompoundDrawables(null, null,drawable, null);
        textViewGift.setCompoundDrawablePadding(15);
    }



    @OnClick({R.id.commission_layout})
    public void onClicks(View view) {
        switch (view.getId()){
            /**佣金详情*/
            case R.id.commission_layout:
                startActivity(new Intent(this, CommissionDetailsActivity.class).putExtra("title", "佣金详情"));
                break;
        }
    }
}
